package top.hudk.tank.factory;

import top.hudk.tank.config.GameConfig;
import top.hudk.tank.config.ResourceMgr;
import top.hudk.tank.constant.GameConstant;
import top.hudk.tank.enums.Dir;
import top.hudk.tank.enums.Group;

/**
 * 作用：
 *
 * @author hudk
 * @date 2020/9/10 8:12
 */
public class DefaultFactory extends AbstractFactory{

    private static DefaultFactory instance = null;

    private DefaultFactory(){
        if(instance != null){
            throw new RuntimeException("本对象是单例模式，系统内不允许多出现个实例");
        }
    }

    /**
     * 单例
     * @return
     */
    public static DefaultFactory getInstance(){
        if(instance == null){
            synchronized(DefaultFactory.class){
                if(instance == null){
                    instance = new DefaultFactory();
                    return instance;
                }
            }
        }
        return instance;
    }

    @Override
    public Tank createGoodTank(){
        DefaultTank defaultGoodTank = new DefaultTank();
        defaultGoodTank.setGroup(Group.GOOD);
        defaultGoodTank.setSpeed(GameConfig.GOOD_TANK_SPEED);
        defaultGoodTank.setWidth(GameConstant.TANK_SIZE);
        defaultGoodTank.setHeight(GameConstant.TANK_SIZE);
        defaultGoodTank.setPlace((GameConfig.GAME_WIDTH + GameConstant.TANK_SIZE) / 2,
                GameConfig.GAME_HEIGHT - GameConstant.TANK_SIZE);
        defaultGoodTank.setDir(Dir.UP);
        defaultGoodTank.setAllowCover(false);
        defaultGoodTank.setGo(true);
        return defaultGoodTank;
    }
    @Override
    public Tank createBadTank(){
        DefaultTank defaulBadTank = new DefaultTank();
        defaulBadTank.setGroup(Group.BAD);
        defaulBadTank.setWidth(GameConstant.TANK_SIZE);
        defaulBadTank.setHeight(GameConstant.TANK_SIZE);
        defaulBadTank.setPlace((GameConfig.GAME_WIDTH + GameConstant.TANK_SIZE) / 2,
                GameConstant.TANK_SIZE);
        defaulBadTank.setDir(Dir.DOWN);
        defaulBadTank.setMoving(true);
        //defaulBadTank.setAllowCover(true);
        return defaulBadTank;
    }

    @Override
    public Bullet createBullet() {
        DefaultBullet defaultBullet = new DefaultBullet();
        defaultBullet.setWidth(ResourceMgr.bulletD.getWidth());
        defaultBullet.setHeight(ResourceMgr.bulletD.getHeight());
        return defaultBullet;
    }

    @Override
    public Explode createExplode() {
        DefaultExplode defaultExplode = new DefaultExplode();
        defaultExplode.setWidth(ResourceMgr.explodes[0].getWidth());
        defaultExplode.setHeight(ResourceMgr.explodes[0].getHeight());
        return defaultExplode;
    }
}
